home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / program / ddj0997.zip / cprog997.txt < prev    next >
Text File  |  1997-07-22  |  2KB  |  111 lines

  1. _C Programming Column_
  2. by Al Stevens
  3.  
  4. Listing One
  5. #include <iostream.h>
  6. #include <string.h>
  7. #include <stdlib.h>
  8.  
  9. int main()
  10. {
  11.     char msg[25];
  12.     strcpy(msg, "The random number is: ");
  13.     cout << msg << rand() << endl;
  14.     return 0;
  15. }
  16.  
  17.  
  18. Listing Two
  19. #ifndef _IOSTREAM
  20. #define _IOSTREAM
  21. namespace std  {
  22.     #include <iostream.h>
  23. }
  24. #endif
  25.  
  26.  
  27. Listing Three
  28. #ifndef _CSTDLIB
  29. #define _CSTDLIB
  30. namespace std  {
  31.     #include <stdlib.h>
  32. }
  33. #endif
  34.  
  35.  
  36. Listing Four
  37. #include <iostream>
  38. #include <cstring>
  39. #include <cstdlib>
  40.  
  41. int main()
  42. {
  43.     char msg[25];
  44.     std::strcpy(msg, "The random number is: ");
  45.     std::cout << msg << std::rand() << std::endl;
  46.     return 0;
  47. }
  48.  
  49.  
  50. Listing Five
  51. // ------- main.cpp
  52. #include <fstream>
  53. using namespace std;
  54.  
  55. void foo(ofstream& ofile);
  56.  
  57. int main()
  58. {
  59.     ofstream ofile("test.txt");
  60.     foo(ofile);
  61.     return 0;
  62. }
  63. // ------- foo.cpp
  64. #include <fstream.h>
  65.  
  66. void foo(ofstream& ofile)
  67. {
  68.     ofile << "Hello Dolly";
  69. }
  70.  
  71.  
  72. Listing Six
  73. #include <fstream>
  74. using namespace std;
  75.  
  76. void foo(ofstream& ofile)
  77. {
  78.     ofile << "Hello Dolly";
  79. }
  80.  
  81.  
  82. Listing Seven
  83. #include <iostream>
  84. #include <cstring>
  85. #include <cstdlib>
  86. using namespace std;
  87.  
  88. int main()
  89. {
  90.     char msg[25];
  91.     strcpy(msg, "The random number is: ");
  92.     cout << msg << rand() << endl;
  93.     return 0;
  94. }
  95.  
  96.  
  97. Listing Eight
  98. #ifndef _IOSTREAM
  99. #define _IOSTREAM
  100.     #include <iostream.h>
  101.     #ifndef using
  102.         #define using     /* */
  103.         #define namespace /* */
  104.         #define std       /* */
  105.     #endif
  106. #endif
  107.  
  108.  
  109.  
  110.  
  111.